package de.hb.bv2.u04;

import java.awt.Shape;
import java.util.ArrayList;
import java.util.Iterator;

public class ContourSet {
	
	public ArrayList<Contour> outerContours;
	public ArrayList<Contour> innerContours;

	ContourSet (int initialSize)
	{
		outerContours = new ArrayList<Contour>(initialSize);
		innerContours = new ArrayList<Contour>(initialSize);
	}

	void addContour(OuterContour oc) 
	{
	outerContours.add(oc);
	}

	void addContour(InnerContour ic) 
	{
	innerContours.add(ic);
	}

	Shape[] getOuterPolygons () 
	{
	return makePolygons(outerContours);
	}

	Shape[] getInnerPolygons () 
	{
	return makePolygons(innerContours);
	}

	Shape[] makePolygons(ArrayList<Contour> nodes) 
	{
		if (nodes == null)
		{
			return null;
		} else {
			Shape[] pa = new Shape[nodes.size()];
			int i = 0;
			Iterator<Contour> itr = nodes.iterator();
			
			while (itr.hasNext()) 
			{
				Contour c = itr.next();
				pa[i] = c.makePolygon();
				i = i + 1;
			}
			
			return pa;
		}
	}

	void moveBy (int dx, int dy) 
	{
		Iterator<Contour> itr;
		itr = outerContours.iterator();
		
		while (itr.hasNext()) 
		{
			Contour c = itr.next();
			c.moveBy(dx,dy);
		}
		
		itr = innerContours.iterator();
	
		while (itr.hasNext()) 
		{
			Contour c = itr.next();
			c.moveBy(dx,dy);
		}
	}

	// utility methods:

	void print() 
	{
		printContours(outerContours);
		printContours(innerContours);
	}

	void printContours (ArrayList<Contour> ctrs) 
	{
		Iterator<Contour> itr = ctrs.iterator();
		
		while (itr.hasNext()) 
		{
			Contour c = itr.next();
			c.print();
		}
	}

}
